﻿using System;
using System.Collections;
using System.Text;
using System.Xml;
using XISoft.AppCreator.Util.Common;
using System.Xml.Serialization;
using XISoft.AppCreator.Util.ICodeCreator;
using System.Windows.Forms;


namespace XISoft.AppCreator.Util.ConfigHelper.CodeConfig
{
    [Serializable]
    [XmlRoot("CodeConfig")]
    public class CodeConfigElement
    {
        private String _name;
        private String _library;
        private String _extension;
        private String _fileName;
        private String _entityCreator;
        private String _dataLayerCreator;
        private String _bussinessLayerCreator;
        private String _typeHelper;
        private String _exeCreator;
        private String _entityTpl;
        private DllLoader dllFile = null;
        
        #region GetObject

        private Object newInstance(String keyName)
        {
            if (dllFile == null)
            {
                dllFile = new DllLoader();
                dllFile.loadLibrary(Application.StartupPath + "\\Modules\\" + Library);
            }
            return dllFile.newInstance(keyName);
        }
        #endregion

        #region getClass
        public ICreateEntity GetEntityCreator()
        {
            return newInstance(EntityCreator) as ICreateEntity;
        }

        public ICreateBussinessLayer getBussinessLayerCreator()
        {
            return newInstance(BussinessLayerCreator) as ICreateBussinessLayer;
        }

        public ICreateDataLayer getDataLayerCreator()
        {
            return newInstance(DataLayerCreator) as ICreateDataLayer;
        }

        public ICreateExe getExeCreator()
        {
            return newInstance(ExeCreator) as ICreateExe;
        }

        public ITypeHelper getTypeHelper()
        {
            return newInstance(TypeHelper) as ITypeHelper;
        }

        #endregion

        #region attribute
        /// <summary>
        /// 名称
        /// </summary>
        [XmlAttribute("Name")]
        public String Name
        {
            get { return _name; }
            set { _name = value;}
        }
        /// <summary>
        /// 类库
        /// </summary>
        [XmlAttribute("Library")]
        public String Library
        {
            get { return _library; }
            set { _library = value; }
        }
        /// <summary>
        /// 扩张名
        /// </summary>
        [XmlAttribute("Extension")]
        public String Extension
        {
            get { return _extension; }
            set { _extension = value; }
        }
        /// <summary>
        /// 临时文件夹
        /// </summary>
        [XmlAttribute("FileName")]
        public String FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }
        #endregion

        #region Element
        /// <summary>
        /// 实体
        /// </summary>
        [XmlElement("EntityCreator")]
        public String EntityCreator
        {
            get { return _entityCreator; }
            set { _entityCreator = value; }
        }
        /// <summary>
        /// 数据访问层
        /// </summary>
        [XmlElement("DataLayerCreator")]
        public String DataLayerCreator
        {
            get { return _dataLayerCreator; }
            set { _dataLayerCreator = value; }
        }
        /// <summary>
        /// DAO
        /// </summary>
        [XmlElement("BussinessLayerCreator")]
        public String BussinessLayerCreator
        {
            get { return _bussinessLayerCreator; }
            set { _bussinessLayerCreator = value; }
        }
        /// <summary>
        /// 类型转换
        /// </summary>
        [XmlElement("TypeHelper")]
        public String TypeHelper
        {
            get { return _typeHelper; }
            set { _typeHelper = value; }
        }
        /// <summary>
        /// 编译
        /// </summary>
        [XmlElement("ExeCreator")]
        public String ExeCreator
        {
            get { return _exeCreator; }
            set { _exeCreator = value; }
        }
        /// <summary>
        /// 实体模板所在的位置
        /// </summary>
        [XmlElement("EntityTpl")]
        public String EntityTpl{
            get { return _entityTpl; }
            set { _entityTpl = value; }
        }
        #endregion
    }
}
